package com.itheima.testjian;

import java.util.ArrayList;
import java.util.Iterator;

public class IteratorCeShi {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("b");
        list.add("d");
        list.add("e");
        list.add("f");

        //删除方法一
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            if("b" .equals(s)){
                list.remove(i);
                i--;
            }
        }
        System.out.println(list);

        System.out.println("--------------------------");

        //删除方法二
        Iterator<String> it = list.iterator();
        while(it.hasNext()){
            String s = it.next();
            if("b" .equals(s)){
                it.remove();
            }
        }
        System.out.println(list);
    }
}
